<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form class="verify-form" :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="患者名称" prop="customerName">
      <el-input v-model="dataForm.customerName" placeholder="患者名称" readonly></el-input>
    </el-form-item>
    <el-form-item label="患者卡号" prop="customerCard">
      <el-input v-model="dataForm.customerCard" placeholder="患者卡号" readonly></el-input>
    </el-form-item>
    <el-form-item label="销售单号" prop="billId">
      <el-input v-model="dataForm.billId" placeholder="销售单号" readonly></el-input>
    </el-form-item>
    <el-form-item label="商品名称" prop="goodsName">
      <el-input v-model="dataForm.goodsName" placeholder="商品名称" readonly></el-input>
    </el-form-item>
    <el-form-item label="商品类别" prop="ctgName">
      <el-input v-model="dataForm.ctgName" placeholder="商品类别" readonly></el-input>
    </el-form-item>
    <el-form-item label="制造商" prop="supplyName">
      <el-input v-model="dataForm.supplyName" placeholder="制造商" readonly></el-input>
    </el-form-item>
    <el-form-item label="商品品种" prop="brandName">
      <el-input v-model="dataForm.brandName" placeholder="商品品种" readonly></el-input>
    </el-form-item>
    <el-form-item label="批次" prop="batch">
      <el-input v-model="dataForm.batch" placeholder="批次" readonly></el-input>
    </el-form-item>
    <el-form-item label="失效日期" prop="invalidTime">
      <el-input v-model="dataForm.invalidTime" placeholder="失效日期" readonly></el-input>
    </el-form-item>
    <el-form-item label="销售门店" prop="deptName">
      <el-input v-model="dataForm.deptName" placeholder="销售门店" readonly></el-input>
    </el-form-item>
    <el-form-item label="销售人员" prop="saleUserName">
      <el-input v-model="dataForm.saleUserName" placeholder="销售人员" readonly></el-input>
    </el-form-item>
    <el-form-item label="销售日期" prop="saleDate">
      <el-input v-model="dataForm.saleDate" placeholder="销售日期" readonly></el-input>
    </el-form-item>
    <el-form-item label="回访标识" prop="returnFlag">
      <!-- <el-input v-model="dataForm.returnFlag" placeholder="回访标识"></el-input> -->
      <el-select v-model="dataForm.returnFlag" placeholder="回访类型" size="mini" disabled>
        <el-option label="未回访" :value="3"></el-option>
        <el-option label="已回访" :value="1"></el-option>
        <el-option label="已取消" :value="2"></el-option>
      </el-select>
    </el-form-item>
    </el-form>
    <el-table :data="dataList" border header-cell-class-name="miui-header-cell-style">
      <el-table-column prop="returnUserName" label="回访人员"></el-table-column>
      <el-table-column prop="returnDate" label="回访时间"></el-table-column>
      <el-table-column prop="returnType" label="回访类型" :formatter="typeFormatter"></el-table-column>
      <el-table-column prop="returnInfo" label="回访信息"></el-table-column>
    </el-table>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
    </span>
  </el-dialog>
</template>

<script>
    import {getObj, addObj, putObj} from '@/api/eims/salereturn'

    export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          customerId: '',
          customerCard: '',
          billId: '',
          goodsId: '',
          ctgId: '',
          supplyId: '',
          brandId: '',
          batch: '',
          invalidTime: '',
          deptId: '',
          salerUserId: '',
          saleDate: '',
          returnFlag: ''
        },
        dataList: [],
        dataRule: {
          customerId: [
            { required: true, message: '患者id不能为空', trigger: 'blur' }
          ],
          customerCard: [
            { required: true, message: '患者卡号不能为空', trigger: 'blur' }
          ],
          billId: [
            { required: true, message: '销售单号不能为空', trigger: 'blur' }
          ],
          goodsId: [
            { required: true, message: '商品id不能为空', trigger: 'blur' }
          ],
          ctgId: [
            { required: true, message: '商品类别不能为空', trigger: 'blur' }
          ],
          supplyId: [
            { required: true, message: '制造商不能为空', trigger: 'blur' }
          ],
          brandId: [
            { required: true, message: '商品品种不能为空', trigger: 'blur' }
          ],
          batch: [
            { required: true, message: '批次不能为空', trigger: 'blur' }
          ],
          invalidTime: [
            { required: true, message: '失效日期不能为空', trigger: 'blur' }
          ],
          deptId: [
            { required: true, message: '销售门店/就诊部门不能为空', trigger: 'blur' }
          ],
          salerUserId: [
            { required: true, message: '销售人员不能为空', trigger: 'blur' }
          ],
          saleDate: [
            { required: true, message: '销售日期不能为空', trigger: 'blur' }
          ],
          returnFlag: [
            { required: true, message: '回访标识(0-未回访,1-已回访)不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            getObj(this.dataForm.id).then(response => {
              if(response.data.code == '0'){
                this.dataForm = response.data.data
                this.dataList = response.data.data.returnLogs
              }else{
                this.$message.error(response.data.msg)
              }
            })
          }
        })
      },
      // 表单提交
      // dataFormSubmit () {
      //   this.$refs['dataForm'].validate((valid) => {
      //     if (valid) {
      //       if (this.dataForm.id) {
      //           putObj(this.dataForm).then(data => {
      //               this.$message.success('修改成功')
      //               this.visible = false
      //               this.$emit('refreshDataList')
      //           });
      //       } else {
      //           addObj(this.dataForm).then(data => {
      //               this.$message.success('添加成功')
      //               this.visible = false
      //               this.$emit('refreshDataList')
      //           })
      //       }
      //     }
      //   })
      // }
      typeFormatter(row, column, cellValue, index) {
        switch (cellValue) {
          case 1:
            return '已回访'
            break
          case 2:
            return '已取消'
            break
          case 3:
            return '未回访'
            break
        }
      },
    }
    
  }
</script>
